package com.buaa.pm.controller;

import com.buaa.pm.entity.OssFile;
import com.buaa.pm.entity.Project;
import com.buaa.pm.model.PageModel;
import com.buaa.pm.model.ResultModel;
import com.buaa.pm.model.dto.ProjectInfoDTO;
import com.buaa.pm.service.PaperService;
import com.buaa.pm.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @Autowired
    private PaperService paperService;

    @PostMapping("/create")
    public ResultModel<Project> createProject(@RequestBody ProjectInfoDTO projectInfoDTO) {
        return ResultModel.success(projectService.createProject(projectInfoDTO));
    }

    @PostMapping("/update")
    public ResultModel<Void> updateProject(@RequestParam String id, @RequestBody ProjectInfoDTO projectInfoDTO) {
        projectService.updateProject(id, projectInfoDTO);
        return ResultModel.success();
    }

    @GetMapping("/page-all")
    public ResultModel<PageModel<Project>> pageAllProject(@RequestParam int pageNum, @RequestParam int pageSize) {
        return ResultModel.success(projectService.pageAllProject(pageNum, pageSize));
    }

    @PostMapping("/upload-instruction")
    public ResultModel<OssFile> uploadInstruction(@RequestPart MultipartFile file) {
        return ResultModel.success(projectService.uploadInstructionFile(file));
    }

    @GetMapping("/get")
    public ResultModel<Project> getById(@RequestParam String projectId) {
        return ResultModel.success(projectService.getProjectById(projectId));
    }

    @PostMapping("/quick-start")
    public ResultModel<Project> quickStart(@RequestParam MultipartFile[] files) {
        return ResultModel.success(paperService.quickStart(files));
    }

}
